/*
 * This file is part of Catfish.
 * Copyright (C) 2010 Namazu Studios LLC
 * 
 * Catfish is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of 
 * the License, or (at your option) any later version.
 * 
 * Catfish is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Catfish.  If not, please visit:
 *  
 * http://www.gnu.org/licenses/
 *  
 */
package com.namazustudios.catfish.callback;

import com.google.appengine.api.datastore.Transaction;

/**
 * Used as a transaction callback. When passed to a Catfish object, it will call
 * the given code between calls to Transaction.begin() and Transaction.commit();
 * If an exception results, this will roll the transaction back. If there is
 * opportunity to retry the transaction, it will re-try the transaction a
 * certain number of times depending on how the Catfish object is configured.
 * 
 * @author patricktwohig
 * 
 * @param <T>
 */
public interface CriticalSection<T, E extends Throwable> {

    /**
     * Performs the given call in the given Transaction.
     * 
     * @param <T>
     * @param trans
     */
    public T call(Transaction trans) throws E;

}
